package com.flyme.module.file.provider.controller;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.file.client.entity.SysCourseComment;
import com.flyme.module.file.client.vo.SysCoursecommentDto;
import com.flyme.module.file.provider.service.SysCourseCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author flyme
 */
@Slf4j
@Api(tags = "课程评论管理")
@RestController
@RequestMapping("/coursecomment")
public class SysCourseCommentController extends BaseController<SysCourseCommentService, SysCourseComment> {


    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/list")
    public ResultBody list(@ModelAttribute PagerInfo pagerInfo, @ModelAttribute SysCoursecommentDto courseComment) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        cq.select("cc.*,u.userName replyUserName");
        cq.eq("targetId", courseComment.getTargetId());
        cq.like("u.userName", courseComment.getUserName());
        String content = Convert.strToUnicode(courseComment.getCommentContent());
        cq.like("cc.commentContent", content.replaceAll("\\\\","_"));
        cq.createAlias("user", "u");
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid);
    }

    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/remove")
    public ResultBody remove(@RequestParam String[] ids) {
        Boolean tag = bizService.removeByIds(CollectionUtil.toList(ids));
        return ResultBody.success(tag);
    }

}
